from flask.blueprints import Blueprint
from flask import Flask
from flask_cors import CORS
from concurrent.futures import ThreadPoolExecutor
from config import config

# 配置跨域
cors = CORS()

# 请求缓存
cache = None


def create_app(config_name: str) -> Flask:
    # 读取配置信息
    app = Flask(__name__)
    app.config.from_object(config[config_name])
    config[config_name].init_app(app)

    
    #  进行一些初始化操作
    # 0. 配置跨域
    cors.init_app(app, resources={
        '/api/*': {'origins': '*'}
    })

   
  

    # 导入不同的蓝图
    from .api import api as api_blueprint
    app.register_blueprint(api_blueprint, url_prefix='/api')  # 导入接口

    # 工厂生产app
    return app